<?php

class Application_Form_LoginForm extends Zend_Form
{

    public function init()
    {
		$decorator = new My_Decorator_SimpleInput();
		$decorator2 = new My_Decorator_SimpleInput2();
		
		$this->setName('Login');
    	$this->setMethod('post');
        
    	//Benutzernummer
    	$nr  = new Zend_Form_Element('nr', array(
        'label'      => 'Benutzernummer',
        'value'      => $this->_nr,
        'validators' => array(
                array('validator' => 'StringLength', 'options' => array(1, 10))
                )
    	));
    	
    	$nr
    	->setRequired()
    	->addErrorMessage('Fehler bei der Benutzernummereingabe');
    	$nr
    	->clearDecorators()
    	->addDecorator($decorator)
    	->addDecorator('Errors');
        
    	//Passwort
    	$passwort  = new Zend_Form_Element('passwort', array(
        'label'      => 'Passwort',
        'value'      => $this->_passwort,
        'validators' => array(
                array('validator' => 'StringLength', 'options' => array(1, 20))
                )
    	));
    	
    	$passwort
    	->setRequired()
    	->addErrorMessage('Fehler bei der Passworteingabe');
    	$passwort
    	->clearDecorators()
    	->addDecorator($decorator2)
    	->addDecorator('Errors');

    	// Submit button
        $submit = new Zend_Form_Element_Submit('anmelden',array('class' => 'button'));
		$submit->setLabel('anmelden');
		
		$form = new Zend_Form();
		
    	
		$this->addElements(array($nr,$passwort,$submit));
    }
    
}

//normaler Decorator
class My_Decorator_SimpleInput extends Zend_Form_Decorator_Abstract
    {
    protected $_format = '<p><label for="%s">%s</label><input id="%s" name="%s" type="text" value="%s"/></p>';
     
    public function render($content)
    {
        $element = $this->getElement();
        $name    = htmlentities($element->getFullyQualifiedName());
        $label   = htmlentities($element->getLabel());
        $id      = htmlentities($element->getId());
        $value   = htmlentities($element->getValue());
     
        $markup  = sprintf($this->_format, $name, $label, $id, $name, $value);
        return $markup;
    }
}


//Decorator für Passwortfeld 
class My_Decorator_SimpleInput2 extends Zend_Form_Decorator_Abstract
{
    protected $_format = '<p><label for="%s">%s</label><input id="%s" name="%s" type="password" value="%s"/></p>';
     
    public function render($content)
    {
        $element = $this->getElement();
        $name    = htmlentities($element->getFullyQualifiedName());
        $label   = htmlentities($element->getLabel());
        $id      = htmlentities($element->getId());
        $value   = htmlentities($element->getValue());
     
        $markup  = sprintf($this->_format, $name, $label, $id, $name, $value);
        return $markup;
    }
}
